import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-07-19
 * Time: 9:07
 */
public class myqueue {
    static class ListNode{
        public int val;
        public ListNode next;
        public ListNode prev;
        public ListNode(int val){
            this.val = val;
        }
    }
    ListNode first;
    ListNode last;
    public void offer(int val){
        ListNode node = new ListNode(val);
        if(first == null){
            first = last = node;
        }else{
            last.next = node;
            node.prev = last;
            last = node;
        }
    }
    public int poll(){  //重点
        if(first == null){
            System.out.println("队列为空，不能进行删除");
            return -1;
        }
        int ret = first.val;
        if(first == last){
            first = last = null; //只有一个节点
            return ret;
        }
        first = first.next;
        first.prev = null;
        return ret;
    }
    public void display(){
        ListNode cur = first;
        while(cur != null){
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
        System.out.println();
    }
}
